﻿using System;
using System.Collections.Generic;
using System.Linq;
using Mal.Balades.Admin.Repositories;
using Mal.Balades.Admin.Services;

namespace Mal.Balades.Admin.ViewModels.VisitViewModels.Edit
{
    public class InformationViewModel : DataViewModelBase
    {

        #region Fields
        IInformation _information;
        int? informationID;
        int? informationTypeID;
        int? visitID;
        string text;
        int? rank;

        private List<IInformationType> informationTypes;
        private IInformationType selectedInformationType;
        #endregion

        #region Construction / Destruction
        public InformationViewModel()
        {
            Initialize();
        }

        public InformationViewModel(IInformation information)
            : this()
        {
            this.Information = information;
        }
        #endregion

        #region enum, struct, class
       
        #endregion

        #region Properties
        private IInformation Information
        {
            get { return _information; }
            set
            {
                _information = value;
                //RaisePropertyChanged("Information");

                this.InformationID = _information.InformationID;
                this.InformationTypeID = _information.InformationTypeID;
                this.Rank = _information.Rank;
                this.Text = _information.Text;
                this.VisitID = _information.VisitID;

            }
        }

        public int? InformationID
        {
            get { return informationID; }
            set
            {
                informationID = value;
                RaisePropertyChanged("InformationID");
            }
        }

        public int? VisitID
        {
            get { return visitID; }
            set
            {
                visitID = value;
                RaisePropertyChanged("VisitID");
            }
        }

        public int? InformationTypeID
        {
            get { return informationTypeID; }
            set
            {
                if (informationTypeID != value)
                {
                    informationTypeID = value;
                    RaisePropertyChanged("InformationTypeID");

                    this.SelectedInformationType = this.InformationTypes.FirstOrDefault(i => i.InformationTypeID == informationTypeID);
                }
            }
        }

        public int? Rank
        {
            get { return rank; }
            set
            {
                rank = value;
                RaisePropertyChanged("Rank");
            }
        }

        public String Text
        {
            get { return text; }
            set
            {
                text = value;
                RaisePropertyChanged("Text");
            }
        }

        public List<IInformationType> InformationTypes
        {
            get { return informationTypes; }
            set
            {
                if (informationTypes != value)
                {
                    informationTypes = value;
                    RaisePropertyChanged("InformationTypes");
                }
            }
        }

        public IInformationType SelectedInformationType
        {
            get { return selectedInformationType; }
            set
            {
                if (selectedInformationType != value)
                {
                    selectedInformationType = value;
                    RaisePropertyChanged("SelectedInformationType");

                    this.InformationTypeID = selectedInformationType.InformationTypeID;
                }
            }
        }
        #endregion

        #region Methods
        private void Initialize()
        {
            this.InformationTypes = Repository.Instance.InformationTypes.Datas;
        }

        protected override bool GetIsChanged()
        {
            return false;
        }
        #endregion

        #region Events

        #endregion

    }
}
